﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
	string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["xxnewsConnectionString"].ConnectionString;
	SqlConnection sqlcon;
	protected void Page_Load(object sender, EventArgs e)
	{
		if (string.IsNullOrEmpty((string)Session["pn"])) Response.Redirect("default.aspx");
		if (!IsPostBack)
		{
			string sqlstr = "";
			if (Session["pn"].ToString() == "段领导")
			{
				sqlstr = "select ch_pwname,in_id FROM siteman2 WHERE (bm_leibie ='段领导') ORDER BY ch_px";
			}
			else
			{
				sqlstr = "select ch_pwname,in_id FROM siteman2 WHERE (ch_bumen = '" + Session["pn"].ToString() + "') ORDER BY ch_px";
			}
			try
			{
				sqlcon = new SqlConnection(strCon);
				SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
				DataSet myds = new DataSet();
				myda.Fill(myds, "siteman2");
				id.DataSource = myds;
				id.DataBind();
			}
			catch (SqlException) { throw; }
		}
		mima.Focus();
		mima.Attributes.Add("onmouseover", "this.focus()");
		mima.Attributes.Add("onfocus", "this.select()");
		id.Attributes.Add("onchange", "mima.focus()");
		if (mima.Text != "")
		{
			try
			{
				string sqlstr1 = "select * from siteman2 where in_id='" + id.SelectedItem.Value + "' and ch_pwd='" + mima.Text + "'";
				sqlcon = new SqlConnection(strCon);
				SqlDataAdapter myda1 = new SqlDataAdapter(sqlstr1, sqlcon);
				DataSet myds1 = new DataSet();
				myda1.Fill(myds1, "siteman1");
				if (myds1.Tables[0].Rows.Count == 0)
				{
					Response.Write("<SCRIPT language=javascript>alert('密码错误！');</SCRIPT>");
				}
				else
				{
					Session["pngeren"] = myds1.Tables[0].Rows[0]["ch_pwname"].ToString();
					if (!string.IsNullOrEmpty((string)Session["lb"]))
					{
						if (Session["lb"].ToString() == "主卡充值" && Session["pn"].ToString() == "材料科")
						{
							Response.Redirect("maincard_recharge.aspx");
						}
						else if (Session["lb"].ToString() == "基础数据" && Session["pn"].ToString() == "设备科")
						{
							Response.Redirect("card_manage.aspx");
						}
						else if (Session["lb"].ToString() == "主卡明细" && (Session["pn"].ToString() == "材料科" || Session["pn"].ToString() == "设备科"))
						{
							Response.Redirect("maincard_detail.aspx?type=" + Request["type"]);
						}
						else if (Session["lb"].ToString() == "油卡明细")
						{
							Response.Redirect("card_detail.aspx?type=" + Request["type"] + "&cardnum" + Request["cardnum"]);
						}
						else//油卡消费
						{
							Response.Redirect("card_use.aspx");
						}
					}
					else
					{
						Response.Redirect("index.aspx");
					}
				}
			}
			catch (SqlException) { throw; }
		}
	}
}
